console.log('深拷贝方法1:...')

let dyx={
    n :1,
    m :2
}
let dyx1 = {...dyx};
dyx.n=2;
console.log(dyx.n);
console.log(dyx1.n);
console.log(dyx==dyx1);


console.log('深拷贝方法2:assign()')

let dyx4=Object.assign({},dyx);//Object.assign()拷贝的是属性值，当源对象中有引用属性时，copy的只是引用值。
console.log(dyx4);
console.log(dyx4==dyx);


console.log('深拷贝方法3-递归遍历法');

let obj = {a:{b:10}};
function deepCopy(obj){
　　if ( typeof obj != 'object' ){ // ( obj  instanceof Object || obj  instanceof Array )
　　　　return obj;
　　}
　　var newobj = {};
　　for ( var attr in obj) {
　　　　newobj[attr] = deepCopy(obj[attr]);
　　}
　　return newobj;
}
var obj2 = deepCopy(obj);
obj2.a.b = 20;
console.log(obj.a.b); //10
console.log(obj2==obj);



console.log('浅拷贝');

let dyx3=dyx;
console.log(dyx3.m);
dyx.m=1
console.log(dyx3.m);
console.log(dyx==dyx3);


